package com.github.llyb120.yaomq.client;

import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.http.HttpUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import java.net.URISyntaxException;

@RequestMapping("/test")
@RestController
public class TestController {

    @RequestMapping("/test1")
    public String test(HttpServletRequest req){
        return "this is test1";
    }

    @RequestMapping("/test2")
    public String fff(){
        return "this is test2";
    }

    @PostConstruct
    public void test() throws URISyntaxException {
        new Thread(() -> {
//            try {
//                Thread.sleep(3000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            YaoMQClient
                .builder()
                .serverUrl("127.0.0.1:8080")
                .clientPort(8090)
                .clientName("test")
                .authToken("1q2w3e4r")
                .build()
                .start();

                ThreadUtil.sleep(1000);
                String body = HttpUtil.createGet("http://localhost:8080/test/test1")
                    .header("yaomq-name", "test")
                    .execute()
                    .body();
                System.out.println("whoops");
                System.out.println(body);
        }).start();
    }
}
